package com.linedata.acq.dao.impl;

import javax.sql.DataSource;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

public class HibernateDAO extends HibernateDaoSupport {

	private Session		sessionFactory	= null;
	private DataSource	dataSource;

	public DataSource getDataSource() {
		return dataSource;
	}

	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}

	public Session getCurrentSession() {
		if (sessionFactory == null) {
			return getSession();
		} else {
			if (sessionFactory.isOpen()) {
				return sessionFactory;
			} else {
				throw new HibernateException("Session is closed " + sessionFactory);
			}
		}
	}

	public void setSessionFactory(Session sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	/**
	 * 
	 */
	public void closeCurrentSession() {
		if (sessionFactory != null && sessionFactory.isOpen()) {
			sessionFactory.close();
			sessionFactory = null;
		}
	}

}
